Skip to content

feat(agents): 会话列表按目录筛选与排序,回答消息数、子代理数、模型和整表计数(API-45 0 内补充) - #219

Merged
xiaoyumuxi merged 2 commits into
mainfrom
feat/agent-sessions-history-fields
Nov 28, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
feat/agent-sessions-history-fields

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

概述 / Summary

API-45(Agent)的一组 agents 0 内补充,给桌面端 1lck/Lithe-IDEA#2492 的 Agent 会话历史页用。桌面端要按“工作区 / 项目 / 全部”过滤会话,按目录分组并显示每组数量,并在每行显示消息数、子代理数、模型和最后一条消息的预览:

  1. 按目录筛选和排序:agentSessions.list 新增 cwdUnder(最多 64 个目录,会话目录就是其中之一或在它下面才保留),以及 order(updated 最近活动在前,默认;started 最近开始在前)。
  2. 整表计数:counts: true 时,回答多出 total(筛选后的会话总数,不受 offset / limit 影响)、groups(按目录给出 {cwd?, count, updatedAtMs?},最近活动在前,最多 500 组)和 groupsTruncated。
  3. 会话活动:每个会话多出四个字段:
    • messageCount:会话自己文件里的可搜索片段数,子代理文件不计;
    • lastMessageRange:最后一个片段的范围,桌面端按需用 agentSessions.read 读出预览,Core 不缓存正文;
    • subagentCount:调用里不同 threadID 的个数;
    • model:最近一次主线程调用的 model,没有时用 requestedModel;全是子代理调用时取最近一次调用的。

不新增宿主方法、通知、错误码、权限、能力版本或 schema 版本。缓存库结构不变,不升 SCHEMA_VERSION。旧 Core 把三个新参数当未知字段拒绝,也不回答四个新字段,桌面端会显示不带这些信息的列表。

宿主方法与通知 / Host methods and notifications

没有新增或修改插件宿主方法。下面这个是平台宿主命令,不是插件宿主方法,列出来方便评审:

原计划编号 名称 种类 用途
API-45 agentSessions.list 平台宿主命令 新参数 cwdUnder、order、counts;每个会话新增 messageCount、subagentCount、model、lastMessageRange;counts 时回答 total、groups、groupsTruncated

主要改动 / Changes

  • rust/crates/agent-sessions/src/store.rs
    • SessionFilter 加 cwd_under 和 order(SessionOrder::Updated / Started)。
    • 筛选条件抽成 selected_sessions! 宏里的两个 CTE,sessions() 和新的 session_counts() 共用。
    • 目录匹配写成 cwd = d OR substr(cwd, 1, length(d)+1) IN (d||'/', d||'\')。目录末尾的 /、\ 先去掉,所以 /w 不会匹配 /wx;/ 和 C:\ 这样的根目录包含它下面的所有路径;超过 64 个目录时返回 InvalidRequest。
    • session_counts() 回答 SessionCounts {total, groups, groups_truncated},组数最多 MAX_SESSION_GROUPS(500)。
    • describe_activity() 用三条有界查询,给当前页的每一行补上消息数和最后一个片段、子代理数、模型。每一行都单独查询,以避开打包的 SQLite 3.46 的一个问题:标量子查询的 ORDER BY 引用外层 CTE 的列时会报 no such column。
  • rust/crates/agent-runtime/src/records.rs:list 接受 cwdUnder、order、counts,检查目录:最多 64 个,每个 1–4096 字节,不能含控制字符,不合格时用 agents.invalidPayload 拒绝。没有允许读取的 Agent 时,回答空列表和零计数。
  • 测试:
    • agent-sessions 新增三个测试,覆盖:
      • 消息数、子代理数、主模型和最后片段的范围,以及子代理文件不计消息;
      • 目录边界:兄弟前缀、末尾分隔符、Windows 路径、根目录、没有 cwd 的会话;
      • 两种排序;
      • 计数不受分页影响,以及按目录分组。
    • 测试解析器补上 thread 和 updated 两个字段。
    • agent-runtime 新增一个测试,用插件后端走完同步、列表、计数,并用 lastMessageRange 读出消息;同时检查五种非法参数被拒绝。
  • 文档:

验证 / Verification

  • cargo test -p lithe-agent-sessions:45 个通过。
  • cargo test -p lithe-agent-runtime:18 个通过。
  • cargo clippy -p lithe-agent-sessions -p lithe-agent-runtime --all-targets -- -D warnings、cargo fmt --check:通过。
  • node shared/plugins/scripts/verify-docs.mjs:通过。
  • 这次不改插件后端协议,所以没跑 sdk-e2e.mjs,四种 SDK 不受影响。

@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 28, 2026 07:29
@xiaoyumuxi
xiaoyumuxi merged commit 690c2d7 into main Nov 28, 2026
11 of 12 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +381 to +385
AND (json_array_length(?5) = 0
OR EXISTS (SELECT 1 FROM json_each(?5) d
WHERE cwd = d.value
OR substr(cwd, 1, length(d.value) + 1)
IN (d.value || '/', d.value || char(92))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Missing sessions under Windows path aliases

cwdUnder drops Windows sessions when the filter spells the same directory with different casing or internal separators. The same comparison undercounts the filtered history.

Learn more

The desktop host passes workspace or project directories to Records::list. The cached cwd comes independently from the session parser and is stored as supplied by write_chunk. The SQL comparison accepts either separator only at the ancestor boundary, not inside the prefix, and compares the prefix case-sensitively. Core's platform layer already documents case-insensitive Windows comparisons and provides separator normalization in relative_path_contains and slash_separated.

Example: A session records C:\Work\App. Filtering by C:\work or C:/Work returns zero sessions and a total of zero even though both name its ancestor.

Recommended fix: Put platform-aware path normalization and containment in lithe-platform and use it for the shared list and count predicate with Platform::HOST. Preserve the original path for display and test both platform rules, equivalent Windows spellings, roots, and sibling prefixes.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +690 to +692
AND COALESCE(c.model, c.requested_model) IS NOT NULL
ORDER BY c.thread_id IS NOT NULL, c.started_at_ms DESC, c.call_key DESC
LIMIT 1";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Session model taken from another call

When the latest main-thread call names no model, describe_activity can display an older call’s model or a subagent’s. The same lookup skips the latest call in subagent-only sessions when it names no model.

Learn more

The session list reports the response model or requested model of the latest main-thread call. The session records contract permits selecting a subagent's latest call only when there are no main-thread calls. Both model names are optional in CallRecord. Filtering out calls with neither name before sorting changes which call wins, rather than returning no model for the winning call.

Example: A main-thread call records model-a, then the next main-thread call records neither model name. Listing the session returns model-a instead of omitting the field. Without the older named main-thread call, a named subagent call can supply the value instead.

Recommended fix: Rank all calls, then read the winning call's COALESCE(model, requested_model) as an Option<String>. Flatten the optional row and optional model. Cover unnamed latest calls in both mixed-thread and subagent-only sessions.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

xiaoyumuxi added a commit that referenced this pull request Nov 28, 2026
…45 0 内补充) (#220)

- 会话事件新增 configOptions(对齐 ACP session config options):最多 16 个设置,每个 1–128 个值,ID 与值唯一,currentValue 必须在列表里;每次报告替换上一次,空列表撤回
- 宿主命令 agents.setConfigOption 只接受用户请求,回合中也可调用,拒绝码 agents.unknownConfigOption、agents.unknownConfigValue、agents.backendUnavailable
- 通知 lithe/host/agents/didSetConfigOption 交给插件后端,四种官方 SDK 新增会话处理器方法
- Go SDK 的宿主通知统一走 Agent 通知分发,去掉重复的方法列表
- 契约 README、fixture、API 总表、更新记录、Agent 功能页同步;#219 移到时间线
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant